package cn.zhp.controller;

import cn.zhp.entity.Result;
import cn.zhp.entity.Statute;
import cn.zhp.service.StatuteService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

@RestController
@RequestMapping("manager/statute")
public class StatuteController {

    @Autowired
    StatuteService service;

    @RequestMapping("index")
    public ModelAndView index() {
        return new ModelAndView("/statute/index");
    }

    @RequestMapping("toUpdate")
    public ModelAndView toUpdate() {
        return new ModelAndView("/statute/update");
    }

    @RequestMapping(value = "selectPage/{pageNum}/{pageSize}")
    public Result selectPage(Integer type, @PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize) {
        PageInfo<Statute> pageInfo = service.selectPage(pageNum, pageSize, type);
        return new Result(true, "查询成功", pageInfo);
    }

    @RequestMapping(value = "doUpdate", method = RequestMethod.PUT)
    public Result doUpdate(@RequestBody Statute statute) {
        //设置更新时间
        statute.setUpdateDate(new Date());
        service.updateByPrimaryKeySelective(statute);
        return new Result(true, "更新成功", null);
    }

}
